package com.log.james.mapper;

import com.log.james.entity.DestIp;
import com.log.james.entity.Fwlog;
import com.log.james.entity.FwlogFlow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface FwlogDao {
    //按照destip这个特性进行组合，后按照数量进行排序
    @Select("SELECT destip,count(id) as num from fwlog GROUP BY destip ORDER BY num DESC limit 1,5")
    List<DestIp> getAccessedIp();

    @Select("select * from fwlog where producetime >= #{st} and producetime < #{et}")
    List<Fwlog> findFwlogsByTime(@Param("st")Date st,@Param("et")Date et);

    /**
     * 根据时间和源ip查找详细信息
     * @param time
     * @param srcip
     * @return
     */
    @Select("select srcip,srcport,destip,destport from fwlog where producetime = #{time} and srcip = #{srcip}")
    List<Map<String,Object>> findFwlogByTimeAndSrcIP(@Param("time")Date time,@Param("srcip")long srcip);

    /**
     * 根据时间和目的端口查找详细的信息
     * @param time
     * @param destport
     * @return
     */
    @Select("select srcip,srcport,destip,destport from fwlog where prodecetime = #{time} and destport = #{destport}")
    List<Map<String,Object>> findFwlogByTimeAndDestPort(@Param("time")Date time,@Param("destport")int destport);

    /**
     * 根据时间和目的ip查找该事件的详细信息
     * @param time
     * @param destip
     * @return
     */
    @Select("select srcip,srcport,destip,destport from fwlog where producetime = #{time} and destip = #{destip}")
    List<Map<String,Object>> findFwlogByTimeAndDestIP(@Param("time")Date time,@Param("destip")long destip);

    /**
     * 获取这个时间段内各个源城市的次数
     * @param st
     * @param et
     * @return
     */
    @Select("SELECT address,count(id) as num FROM fwlog WHERE producetime >= #{st} and producetime <= #{et} GROUP BY address ORDER BY num DESC")
    List<Map<String,Object>> findCityNumByTime(@Param("st")Date st,@Param("et")Date et);

    /**
     * 协议组的情况
     * @param st
     * @param et
     * @return
     */
    @Select("select port,sum(count) as num from fwlogprotocol where starttime >= #{st} and endtime <= #{et} group by port order by num desc")
    List<Map<String,Object>> findProtocolByTime(@Param("st")Date st,@Param("et")Date et);
}
